unit BayiGeriBildirim;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxDBLookupComboBox, cxTimeEdit,
  cxRichEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  ExtCtrls, StdCtrls, Buttons, wwdblook, wwdbdatetimepicker, Mask,
  wwdbedit, XPMan, StdActns, ActnList, ADODB, cxMemo, ComCtrls, wwriched,
  DBCtrls, siComp;

type
  TfmBayiGeriBildirim = class(TfmFormClass)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    edKayitNo: TwwDBEdit;
    dtBasTarih: TwwDBDateTimePicker;
    dtBitTarih: TwwDBDateTimePicker;
    lcFlag: TwwDBLookupCombo;
    lcTur: TwwDBLookupCombo;
    btListele: TBitBtn;
    Panelx: TPanel;
    byeni: TBitBtn;
    bkapat: TBitBtn;
    btYeni: TBitBtn;
    btSil: TBitBtn;
    btDuzelt: TBitBtn;
    btIncele: TBitBtn;
    cxGrid2: TcxGrid;
    grdListe: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    AramaQ: TADOQuery;
    AramaQS: TDataSource;
    dsFirm: TDataSource;
    aqFirm: TADOQuery;
    aqStore: TADOQuery;
    dsStore: TDataSource;
    aqNeedType: TADOQuery;
    dsNeedType: TDataSource;
    aqFlag: TADOQuery;
    dsFlag: TDataSource;
    grdListepkNeedId: TcxGridDBColumn;
    grdListefkFirmId: TcxGridDBColumn;
    grdListefkStoreId: TcxGridDBColumn;
    grdListefkNeedTypeId: TcxGridDBColumn;
    grdListefkFlagId: TcxGridDBColumn;
    grdListeneedText: TcxGridDBColumn;
    grdListeenteredDate: TcxGridDBColumn;
    lcFirma: TwwDBLookupCombo;
    Label6: TLabel;
    lcStore: TwwDBLookupCombo;
    Label8: TLabel;
    alMain: TActionList;
    acListele: TAction;
    acEkle: TAction;
    acSil: TAction;
    acGuncelle: TAction;
    acincele: TAction;
    GroupBox2: TGroupBox;
    moAciklama: TDBMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure bkapatClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure acListeleExecute(Sender: TObject);
    procedure acEkleExecute(Sender: TObject);
    procedure acSilExecute(Sender: TObject);
    procedure acGuncelleExecute(Sender: TObject);
    procedure acinceleExecute(Sender: TObject);
    procedure grdListeDblClick(Sender: TObject);
    procedure AramaQAfterScroll(DataSet: TDataSet);
    procedure grdListeDataControllerFilterChanged(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmBayiGeriBildirim: TfmBayiGeriBildirim;

implementation
uses ana1, data, unitgenel, unitOrtak, BayiGeriBildirimKart;
{$R *.dfm}

procedure TfmBayiGeriBildirim.FormCreate(Sender: TObject);
begin
  inherited;
  aqFirm.Open;
  aqStore.Open;
  aqNeedType.Open;
  aqFlag.Open;
end;

procedure TfmBayiGeriBildirim.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmBayiGeriBildirim := nil;
end;

procedure TfmBayiGeriBildirim.bkapatClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfmBayiGeriBildirim.FormShow(Sender: TObject);
begin
  inherited;
  dtBasTarih.Date := date - 1;
  dtBitTarih.Date := date;
  acListeleExecute(nil);
end;

procedure TfmBayiGeriBildirim.acListeleExecute(Sender: TObject);
var
  SqlTop: string;
begin
  inherited;
  SqlTop := '';
  if (Sender = nil) then
    SqlTop := 'Top 100';

  AramaQ.SQL.Text := ' Select ' + SqlTop + ' * from Need ';

  if (Anaform.SuperVisor) then
    AramaQ.SQL.Add(' Where 1=1 ')
  else
    AramaQ.SQL.Add(' Where 1=2 ');

  if Trim(edKayitNo.Text) <> '' then
    AramaQ.SQL.Add(' and pkNeedId=' + Trim(edKayitNo.Text));

  if Trim(lcFirma.Text) <> '' then
    AramaQ.SQL.Add(' and fkFirmId=' + lcFirma.LookupValue);

  if Trim(lcStore.Text) <> '' then
    AramaQ.SQL.Add(' and fkStoreId=' + lcStore.LookupValue);

  if Trim(lcTur.Text) <> '' then
    AramaQ.SQL.Add(' and fkNeedTypeId=' + lcTur.LookupValue);

  if Trim(lcFlag.Text) <> '' then
    AramaQ.SQL.Add(' and fkFlagId=' + lcFlag.LookupValue);

  if Trim(dtBasTarih.Text) <> '' then
    AramaQ.SQL.Add(' and enteredDate>="' + TarihDonustur(dtBasTarih.date, srvcasper, '') + '"');

  if Trim(dtBitTarih.Text) <> '' then
    AramaQ.SQL.Add(' and enteredDate<="' + TarihDonustur(dtBitTarih.date + 1, srvcasper, '') + '"');

  AramaQ.SQL.Add(' Order By pkNeedId DESC');

  OpenQueryOnDataSet(AramaQ.SQL.Text, AramaQ);

  Caption := 'Bayi Geri Bildirim Listesi (' + inttostr(grdListe.DataController.RowCount) + ')';
end;

procedure TfmBayiGeriBildirim.acEkleExecute(Sender: TObject);
begin
  inherited;
  fmBayiGeriBildirimKart := TfmBayiGeriBildirimKart.Create(Self, Self, fsMDIChild, futEdit, '0');
  Anaform.yetkiayarla(fmBayiGeriBildirimKart);
  YerAyarla(fmBayiGeriBildirimKart, false);
end;

procedure TfmBayiGeriBildirim.acSilExecute(Sender: TObject);
begin
  inherited;
//
end;

procedure TfmBayiGeriBildirim.acGuncelleExecute(Sender: TObject);
begin
  inherited;
  if (AramaQ.RecNo > 0) then
  begin
    fmBayiGeriBildirimKart := TfmBayiGeriBildirimKart.Create(Self, Self, fsMDIChild, futEdit, AramaQ.FieldByName('pkNeedId').AsString);
//    fmBayiGeriBildirimKart.UseType := futEdit;
//    fmBayiGeriBildirimKart.USEID := AramaQ.FieldByName('pkNeedId').AsString;
    Anaform.yetkiayarla(fmBayiGeriBildirimKart);
    YerAyarla(fmBayiGeriBildirimKart, false);
//    fmBayiGeriBildirimKart.FormStyle := FSMDIChild;
//    fmBayiGeriBildirimKart.FShow(fmBayiGeriBildirimKart);
  end;
end;

procedure TfmBayiGeriBildirim.acinceleExecute(Sender: TObject);
begin
  inherited;
  if (AramaQ.RecNo > 0) then
  begin
    fmBayiGeriBildirimKart := TfmBayiGeriBildirimKart.Create(Self, Self, fsMDIChild, futInspection, AramaQ.FieldByName('pkNeedId').AsString);
  end;
end;

procedure TfmBayiGeriBildirim.grdListeDblClick(Sender: TObject);
begin
  inherited;
  if (acGuncelle.Visible) and (acGuncelle.Enabled) then
    acGuncelle.Execute
  else
    if acincele.Visible then
      acincele.Execute;
end;

procedure TfmBayiGeriBildirim.AramaQAfterScroll(DataSet: TDataSet);
begin
  inherited;
  if (acGuncelle.Visible) then
    acGuncelle.Enabled := (AramaQ.FieldByName('fkFirmId').AsInteger = 12) and (AramaQ.FieldByName('fkStoreId').AsInteger = 101) and (AramaQ.FieldByName('fkUserId').AsInteger = 143);
end;

procedure TfmBayiGeriBildirim.grdListeDataControllerFilterChanged(
  Sender: TObject);
begin
  inherited;
  Caption := 'Bayi Geri Bildirim Listesi (' + inttostr(grdListe.DataController.RowCount) + ')';
end;

end.